package com.ws.test07.test;

import com.ws.test07.entity.Student;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 王硕
 * @version jdk21
 * @className test
 * @description
 * @date 2024/11/21 21:38
 */
public class test {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        students.add(new Student().setName("张三").setAge(18).setScore(85.5));
        students.add(new Student().setName("黄三").setAge(18).setScore(65.5));
        students.add(new Student().setName("张四").setAge(18).setScore(75.5));
        students.add(new Student().setName("李三").setAge(18).setScore(95.5));
        students.add(new Student().setName("王三").setAge(18).setScore(15.5));
        students.add(new Student().setName("张六月").setAge(18).setScore(25.5));
        students.add(new Student().setName("张是").setAge(18).setScore(45.5));
        students.add(new Student().setName("手机号").setAge(18).setScore(45.5));
        students.add(new Student().setName("sah").setAge(18).setScore(85.5));
        students.add(new Student().setName("ju三").setAge(18).setScore(85.5));
        students.add(new Student().setName("er三").setAge(18).setScore(85.5));
        double sum = 0;
        int count = 0;
        for (Student student : students) {
            if (student.getName().startsWith("张")) {
                sum += student.getScore();
                count++;
            }
        }
        double average = count > 0 ? sum / count : 0;
        System.out.println("姓张的同学的平均成绩是：" + average);
    }
}
